package com.joolun.mall.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.joolun.common.utils.SecurityUtils;
import com.joolun.mall.entity.ChainDetail;
import com.joolun.mall.mapper.ChainDetailMapper;
import com.joolun.mall.service.IChainDetailService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 品牌Service业务层处理
 * 
 * @author www.joolun.com
 * @date 2025-05-20
 */
@Service
public class ChainDetailServiceImpl extends ServiceImpl<ChainDetailMapper, ChainDetail> implements IChainDetailService
{

    @Transactional
    @Override
    public void deleteDetails(List<Long> ids) {
        if(CollectionUtil.isNotEmpty(ids)){
            ChainDetail chainDetail = new ChainDetail();
            //todo 校验需要做
            this.update(Wrappers.query(chainDetail).lambda().in(ChainDetail::getId, ids));

            ChainDetail query = new ChainDetail();
            query.setDelFlag("0");
            List<ChainDetail> deleteDetails = this.list(
                    Wrappers.query(query).lambda().in(ChainDetail::getChainId, ids)
            );
            //删除
            if(CollectionUtil.isNotEmpty(deleteDetails)){
                deleteDetails.forEach(e -> {
                    e.setDelFlag("2");
                    e.setUpdateTime(new Date());
                    e.setUpdateBy(SecurityUtils.getUsername());
                });
                updateBatchById(deleteDetails);
            }
        }
    }
}
